const app = getApp()
Page({
  data: {
    isManage:false,
    startBarHeight:app.globalData.startBarHeight,
    user:{
      bank: {money:0, tobo_paid:0,point:0},
      num: {fans:0, store:0, vip: 0}
    },
    config:{},
    adwords:[]
  },
  //监听页面初次载入完成
  onLoad: function (options) {
    app.getParam(options);
  },
  //生命周期函数--监听页面显示
  onShow: function () {
    app.loginState((state)=>{
      this.setData({
        loginstate:state,
        ucode:state ? app.globalData.loginuser.ucode:'',
      })
      if(state){
        this.getApi();
        this.getBank();
      }
    },false)
    app.appConfig((rel)=>{
      this.setData({config:rel})
    });
  },
  //会员服务
  getApi:function () {
    app.api().Get('api/v1/ais/index/adwords',{ids:'user'},(result) => {
      if (result.code == 200) {
        this.setData({
          adwords:result.data
        })
      }
    })
  },
  //获取会员数据
  getBank:function () {
    app.api().Get("api/v1/ais/user/analysis",(rel) => {
      if(200 == rel.code){
        this.setData({
          user:rel.data
        }) 
      }
    })
  },
  //拨打电话
  callPhone:function (e) {
    app.callPhone(e);
  },
  //一键复制事件
  copyBtn: function () {
    wx.setClipboardData({
      data: '开通会员填写我的邀请码【 ' + app.globalData.loginuser.ucode +' 】和我一起省钱,还能赚钱.',
      success:(res) =>{
        wx.showToast({
          title: '复制成功',
        });
      }
    });
  },
  onLoginState: function (e) {
    if(e.detail.state == true){
      app.appConfig((rel)=>{
        this.setData({
          config: rel,
          loginstate:true,
          ucode:app.globalData.loginuser.ucode,
        })
        if(app.util().isNull(rel.user_bindphone)){
          wx.navigateTo({
            url: '/packageHelper/pages/bindphone',
          })
        }
      });
    }
  },
  onLogin: function () {
    this.setData({
      loginstate:false,
    })
  },
  //转发
  onShareAppMessage: function (res) {
    return {
      title: app.globalData.appConfig.shore_text,
      path: '/tab/index?ucode='+app.globalData.ucode
    }
  },
  //滚动
  onPageScroll(res) {
    let scrollTop = res.scrollTop;
    this.setData({
      showbar:60 <= scrollTop ? true : false
    })
  },
  //开通会员
   onUrl:function (e) {
    if(this.data.loginstate){
      wx.navigateTo({
        url:e.currentTarget.dataset.url
      }) 
    }else{
      wx.navigateTo({
        url:'/packageHelper/pages/login',
      })
    }
  },
})